<template>
  <div class="order-item">
    <div class="title">
      <div class="name" :name-text="titleInfos.title">
        {{ titleInfos.title }}
      </div>
      <div class="status-name" :style="{ color: titleInfos.orderStatusDescColor }">
        {{ titleInfos.statusName }}
        <span class="sub-name">{{ titleInfos.cancelReasonDesc }}</span>
      </div>
    </div>
    <div class="swiper">
      <img :src="itemData.unitPicture" alt="">
      <div class="bottom">
        <div class="left">
          <div class="date-box date-left">
            <span class="date">
              {{ formatWeek(swiperData.checkInDate) }}
            </span>
            <!-- 星期 -->
            <div class="week">
              <span>
                {{ formatWeek(swiperData.checkInDate, true) }}
              </span>
              <span>
                {{ swiperData.checkInLatestTime }}</span>
            </div>
          </div>
          <img class="icon" src="../../../assets/img/order/icon_right_orderlist.png" alt="">
          <div class="date-box date-right">
            <span class="date">
              {{ formatWeek(swiperData.checkOutDate) }}
            </span>
            <!-- 星期 -->
            <div class="week">
              <span>
                {{ formatWeek(swiperData.checkOutDate, true) }}
              </span>
              <span>
                {{ swiperData.checkOutLatestTime }}
              </span>
            </div>
          </div>
        </div>
        <div class="right">
          <span class="text">支付总价</span>
          <span class="price">￥{{ swiperData.prepayAmount }}</span>
        </div>
      </div>
    </div>
    <div class="infos">
      <div class="left">
        <div class="left-content" v-if="infos.countdown">
          <img src="@/assets/img/order/icon-time.png" alt="">
          <span class="time">{{ infos.countdown }}分</span>
          <span class="text">后订单自动取消</span>
        </div>
      </div>
      <div class="right">
        <div class="btn-content" v-if="infos.orderStatus === 1">
          <button class="btn connect">联系房东</button>
          <button class="btn pay">去支付</button>
        </div>
        <div class="btn-content" v-if="infos.orderStatus === 5">
          <button class="btn remove">删除</button>
          <button class="btn order">再次预定</button>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { watch, computed, ref } from 'vue';
import { formatWeek } from "@/utils/format_date"
const props = defineProps({
  itemData: {
    type: Object,
    default: () => ({})
  }
})
const orderItem = ref({})
watch(props.itemData, (newVal, oldVal) => {
  orderItem.value = newVal
}, {
  immediate: true,
  deep: true
})

const titleInfos = computed(() => {
  const data = orderItem.value
  return {
    title: data.unitName,
    statusName: data.orderStatusDesc,
    cancelReasonDesc: data.cancelReasonDesc,//是否取消
    orderStatusDescColor: data.orderStatusDescColor //字体颜色
  }
})
const swiperData = computed(() => {
  const data = orderItem.value
  return {
    checkInDate: data.checkInDate,
    checkInLatestTime: data.checkInLatestTime,
    checkOutDate: data.checkOutDate,
    checkOutLatestTime: data.checkOutLatestTime,
    prepayAmount: data.prepayAmount //预付款
  }
})
const infos = computed(() => {
  const data = orderItem.value
  return {
    countdown: Math.round(data.countdown / 60), // 剩余支付秒
    orderStatusDesc: data.orderStatusDesc,
    orderStatus: data.orderStatus, // 1 待支付  0 取消
  }
})

</script>

<style lang="less" scoped>
.order-item {
  padding: 0 20px;
  margin-top: 10px;
  background-color: #f7f8fb;

  .title {
    display: flex;
    justify-content: space-between;
    align-items: center;

    .name {
      max-width: 204px;
      font-size: 14px;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
      padding: 20px 0;
      position: relative;
    }

    .status-name {
      font-size: 18px;
      font-weight: 500;

      .sub-name {
        font-size: 13px;
      }
    }


  }

  .swiper {
    height: 223px;
    position: relative;

    img {
      width: 100%;
      height: 100%;
      border-radius: 6px;
    }

    .bottom {
      height: 60px;
      position: absolute;
      bottom: 0;
      left: 0;
      background: rgba(9, 10, 14, 0.7);
      display: flex;
      align-items: center;
      color: #fff;

      .left {
        display: flex;
        align-items: center;

        .date-box {
          display: flex;
          flex-direction: column;
          align-items: center;
          padding: 0 20px;


          .date {
            margin-bottom: 6px;
            font-size: 16px;
            line-height: 16px;
          }

          .week {
            font-size: 12px;
            opacity: 0.8;

          }
        }

        .icon {
          width: 15px;
          height: 15px;
        }
      }

      .right {
        position: relative;
        width: 122px;
        height: 100%;
        display: flex;
        flex-direction: column;
        justify-content: center;
        align-items: center;

        .text {
          font-size: 13px;
          opacity: 0.8;
        }

        .price {
          font-size: 16px;
          list-style: 16px;
          color: var(--primary-color);
          margin-top: 5px;
          transform: scale(0.9) //大于1放大，小于1缩小
        }

        &::before {
          content: "";
          width: 1px;
          height: 40px;
          position: absolute;
          left: 0;
          top: 10px;
          background-color: white;
        }

      }
    }
  }

  .infos {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 60px;

    .left {
      display: flex;
      align-items: center;
      font-size: 12px;
      color: #666;


      img {
        width: 11px;
        height: 11px;
        margin-right: 3px;
      }

      .time {
        color: var(--primary-color)
      }
    }

    .right {
      .btn-content {
        display: flex;
        justify-content: space-between;
        align-items: center;

        .btn {
          display: inline-block;
          text-align: center;
          line-height: 30px;
          margin-left: 10px;
          border: 1px solid #e9e9e9;
          color: #666;
          background-color: #fff;
          border-radius: 6px;
          font-size: 14px;
          min-width: 75px;
        }


        .pay {
          background-color: var(--primary-color);
          color: #fff
        }

        .order {
          border: 1px solid var(--primary-color);
        }
      }
    }
  }
}
</style>